"use strict";
var wpsapi;
(function (wpsapi) {
    const appid = "AK20220114NTEJII";
    const appkey = "c9e6a6fa35bbb57f4afe3e27a58ec8f7";
    const host = "https://openapi.wps.cn";
    const redirect = "https://fxzqf.gitee.io/testwpsapi.html";
    const href = host + "/oauthapi/v2/authorize?response_type=code&appid=" + appid + "&autologin=true&redirect_uri=" + redirect + "&scope=user_info,cloud_file,file_selector&state=STATE";
    class client {
        constructor() {
        }
    }
    window.onload = () => {
        let pramas = new URLSearchParams(window.location.href.split('?')[1]);
        let code = null;
        if (typeof pramas != "undefined")
            code = pramas.get("code");
        if (code == null)
            window.location.href = href;
        const data = null;
        const xhr = new XMLHttpRequest();
        xhr.withCredentials = true;
        xhr.addEventListener("readystatechange", function () {
            if (this.readyState === this.DONE) {
                if (this.response == '{"result":100016,"msg":"InvalidCode"}')
                    window.location.href = href;
                wpsapi.token = JSON.parse(this.responseText);
                console.log(wpsapi.token);
                /*
                const xhr1 = new XMLHttpRequest();
                xhr1.addEventListener("readystatechange", function () {

                    console.log(this.responseText);
                })
                xhr1.open("GET","https://openapi.wps.cn/oauthapi/v3/app/files/list?access_token="+token.token.access_token+"&appid=AK20220114NTEJII");
                xhr1.setRequestHeader("Content-Type","application/json");
                xhr1.send(data);        */
            }
        });
        let access_token = '452492db6dc30b2577ddad667e20c1cc';
        let rpc_token = "5jdq8d8v7sZRvsCQP1nsjdG6InIoceRb208OOZGnySM";
        //452492db6dc30b2577ddad667e20c1cc', refresh_token: '21b82b264fa1e6941523db7c3a2f0c88'
        xhr.open("GET","https://openapi.wps.cn/oauthapi/v3/app/files/list?access_token="+access_token+"&appid=AK20220114NTEJII&open_parentid=0");
        //xhr.open("POST","https://openapi.wps.cn/oauthapi/v2/rpc/token?access_token="+access_token+"&appid="+appid+"&scope=user_info,cloud_file,file_selector");
        //xhr.open("GET", host + "/oauthapi/v2/token?appid=" + appid + "&appkey=" + appkey + "&code=" + code);
        //xhr.setRequestHeader("Content-Type", "application/json");
        xhr.send(data);
        /*
        console.log(xhr.responseText);
        token=JSON.parse(xhr.responseText);
        xhr.open("GET", "https://openapi.wps.cn/oauthapi/v3/app/files/list?access_token="+token.token.access_token+"&appid=AK20220114NTEJII",true);
        xhr.setRequestHeader("Content-Type","application/json")
        xhr.send(data);
        console.log(xhr.responseText);
        */
    };
})(wpsapi || (wpsapi = {}));
